﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using Gallio.Framework;
using MbUnit.Framework;
using MbUnit.Framework.ContractVerifiers;
using Moq;

namespace Nvigorate.Repository.Test
{
    [TestFixture]
    public class SearchCriteriaFixture
    {
        [Test]
        public void Criteria_BuildUp()
        {
            var criteria = new SearchCriteria<Person>()
                .Add(person => person.FirstName == "Alex")
                .Add(person => person.LastName == "Robson")
                .Add(person => person.Age >= 30);

            var target = new List<Person>()
                             {
                                 new Person() { Age = 1, FirstName = "Billy", LastName = "Bloomhurst"},
                                 new Person() { Age = 3, FirstName = "Alex", LastName = "Robson"},
                                 new Person() { Age = 30, FirstName = "Alex", LastName = "NotRobson"},
                                 new Person() { Age = 30, FirstName = "Fake", LastName = "Robson"},
                                 new Person() { Age = 30, FirstName = "Alex", LastName = "Robson"},
                                 new Person() { Age = 27, FirstName = "Alex", LastName = "Robson"},
                             }.AsQueryable();

            var queryable = from p in target select p;

            var result = criteria.Filter(queryable);

            Assert.AreEqual(1, result.Count());
        }
    }
}
